ratings = [1, 2, 2]
ratings = [1, 0, 2]
ratings = [1, 1]
ratings = [1, 3, 2, 2, 1]

var candy = function (ratings) {
    let len = ratings.length
    if (len === 1) return 1
    if (len === 2 && ratings[0] !== ratings[1]) return 3
    if (len === 2 && ratings[0] === ratings[1]) return 2
    let num = 2
    if (ratings[0] > ratings[1]) num++
    if (ratings[len - 1] > ratings[len - 2]) num++
    for (let i = 1; i < len - 1; i++) {
        num++
        if (ratings[i] > ratings[i - 1] && ratings[i] > ratings[i + 1]) {
            num += 2
        } else if (ratings[i] > ratings[i - 1] || ratings[i] > ratings[i + 1]) {
            num++
        }
    }
    return num
};
console.log(candy(ratings));
